Skip to content

id: hosted export production — DO enumeration and R2 blobs into build_export (slice 4b of #2852) - #13212

Merged
dezren39 merged 2 commits into
mainfrom
lane-qn-13157
Nov 23, 2026
Merged

dezren39 merged 2 commits into
mainfrom
lane-qn-13157

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Slice 4b (production half) of #2852: produce a real §6 export from a live hosted per-user store. Design + mapping record: the design comment on #13157; the mapping is also recorded in the spec as §6.3.

Data plane (hosted-worker)

  • New src/export.ts: produceExportSets enumerates the DO's applied events (BridgeStore.appliedEvents()) and fetches the R2 blobs they cite, producing the §6 object/blob sets in canonical (hash) order with counts and the concatenated-hash digest. A referenced blob R2 cannot produce — or a citation no referenced blob satisfies — fails production loudly, naming the hash.
  • New route GET /v1/bridge/export, ID-key proof like the other bridge HTTPS legs (new "export" auth context). Pure read: available from a read-only, at-cap store.
  • SignedEvent now exposes the envelope signature it already parsed.

Object-model mapping (§6.3)

  • Export bytes are the stored envelope verbatim — never re-encoded, never re-signed. Export hash = SHA-256 of the envelope bytes; signer = envelope author; signature = the envelope's own.
  • hosted_export.rs: ExportObject::from_envelope + cited_content_hashes replace the synthetic sign-over-hash constructor; verify_import step 3 verifies an object by decoding its envelope exactly as chain.rs does. Document citations (BLAKE3, native) resolve to the export's SHA-256 blob names by content.

Defect found by the rebind-history acceptance case, fixed at the root

  • HostedBindingService::verify_key_signature required the ceremony transcript's key to be the record's current key, so no post-rebind record could ever verify — a rebind-history export was impossible. The transcript's key must now be the current key or a history key; the record's current shape stays covered by the service attestation (checked alongside in §6.2 step 2).

Verification (reference laptop; the dispatch container cannot run this suite — no Node.js and the #13159 nix gaps — so per the dispatch-first fallback the verifying route is local, recorded here)

  • cargo test -p id --lib — 531 passed, 0 failed (includes 13 hosted_export tests: the reworked 4a set on real envelopes, the fixture contract, the rebind-history export; and all hosted_binding tests).
  • hosted-worker npm test — 121 passed, 0 failed, including 5 new export tests (seeded DO → sets; at-cap availability; both loud-failure legs; proof fail-closed).
  • Cross-language contract: the worker suite pins the produced sets to test/fixtures/hosted-export-sets.json (seed key [7;32]); the Rust suite feeds the same fixture through build_export + verify_import — counts 4/2 and the digest match.
  • cargo fmt clean on the touched Rust files (three test files carry pre-existing fmt drift on main, left untouched). Clippy: no findings in the touched files beyond warn-level pedantic notes; the workspace's clippy run stops earlier on pre-existing expect() errors in crates/id-store/src/admission.rs test code (untouched here, the id phase-8: P8.8 clippy/lint sweep deferred — ~150 clippy warnings remain with no tracking issue #803-family debt).

Acceptance mapping: export from a seeded DO passes verify_import with matching counts/digest (fixture contract test); producible at cap (worker test); missing blob fails loudly naming the hash (both legs, worker tests); enumeration mapping covered incl. multiple objects citing multiple blobs, one blob cited twice, and a rebind-history store (Rust test).

Closes #13157

Update — reconciled with #13158 (ingest half, landed on main while this PR was open): merged main in (e042850). Doc conflict in hosted_export.rs resolved by keeping the production section and pointing ingest at hosted_ingest. Semantic conflict: hosted_ingest's tests built objects with the removed ExportObject::new — migrated to ExportObject::from_envelope; its not-an-event test's premise (a wrapper-valid non-event object) is exactly what §6.3 overturns, so it now asserts the refusal at verify_import (ObjectSignatureInvalid). Merged tree re-verified: cargo test -p id --lib — 535 passed, 0 failed.

…_export (slice 4b of #2852, #13157)

Production half of the §6 export: the hosted data plane now
produces the object/blob sets build_export assembles.

- hosted-worker/src/export.ts: produceExportSets maps a per-user
  DO's applied events (BridgeStore.appliedEvents) and the R2 blobs
  they cite into the §6 sets, in canonical order, with counts and
  the concatenated-hash digest. A referenced blob R2 cannot
  produce, or a citation no referenced blob satisfies, fails the
  export loudly naming the hash.
- GET /v1/bridge/export on the DO, ID-key proof like the other
  bridge HTTPS legs (new "export" auth context). Pure read:
  available from a read-only, at-cap store.
- SignedEvent exposes the envelope signature (parsed already,
  never surfaced before).

Object-model mapping (§6.3 in the spec doc): export bytes are the
stored envelope verbatim — never re-encoded, never re-signed;
the export hash is SHA-256 of the envelope bytes; signer and
signature are the envelope's author and its own signature.
hosted_export.rs follows: ExportObject::from_envelope +
cited_content_hashes replace the synthetic sign-over-hash
constructor, and verify_import step 3 verifies an object by
decoding its envelope as chain.rs does. Document citations
(BLAKE3, native) resolve to the export's SHA-256 blob names by
content.

Defect found by the rebind-history acceptance case and fixed at
the root: HostedBindingService::verify_key_signature required
the ceremony transcript's key to be the record's current key, so
no post-rebind record could ever verify. The transcript's key is
now required to be the current key or a history key; the current
shape stays covered by the service attestation.

Cross-language contract: the worker suite seeds a DO from a
fixed seed key and pins the produced sets to
test/fixtures/hosted-export-sets.json; the Rust suite feeds the
same fixture through build_export + verify_import.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bbbe961a-ca8d-4694-8dd7-399c6ff7524c
Commits

Reviewing files that changed from the base of the PR and between 52d0d4d and e042850.

Files selected for processing: 13

  • doc/2026-10-30T22-45-00Z_design_hosted_provisioning_sso_binding.md
  • pkgs/id/hosted-worker/README.md
  • pkgs/id/hosted-worker/package.json
  • pkgs/id/hosted-worker/src/bridge-auth.ts
  • pkgs/id/hosted-worker/src/bridge-store.ts
  • pkgs/id/hosted-worker/src/event.ts
  • pkgs/id/hosted-worker/src/export.ts
  • pkgs/id/hosted-worker/src/user-do.ts
  • pkgs/id/hosted-worker/test/export.test.ts
  • pkgs/id/hosted-worker/test/fixtures/hosted-export-sets.json
  • pkgs/id/src/hosted_binding.rs
  • pkgs/id/src/hosted_export.rs
  • pkgs/id/src/hosted_ingest.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T11:26:50.508450Z e042850 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7cdcf8e1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +591 to +593
if hex_encode(event.header.verifying_key.as_bytes()) != object.signer
|| !chain_keys.contains(&object.signer.as_str())
|| hex_encode(&event.header.signature.to_bytes()) != object.signature

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Make multi-author bridge exports importable

When a bridge store contains events authored by other users, the new producer exports those events verbatim, but this check rejects the resulting archive with ObjectSignatureInvalid because their authors are not in the exporting user's binding history. This is a supported bridge scenario: hosted-worker/test/bridge-session.test.ts:151–172 authenticates with one bound key while synchronizing Alice's and Bob's separately authored chains. Reconcile the import authorization policy with the producer's complete applied-event set so normal collaborative stores can be exported and restored without discarding other authors' objects.

Useful? React with 👍 / 👎.

blob_refs: o.blob_refs,
bytes: [...o.bytes],
})),
blobs: sets.blobs.map((b) => ({ hash: b.hash, bytes: [...b.bytes] })),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stream blob bytes instead of expanding the whole export in memory

For stores containing moderately large blobs, this expands every buffered blob into a JavaScript number array before user-do.ts additionally stringifies the entire response. The Worker/DO has a 128 MB isolate memory budget, while blob uploads permit up to 100 MiB and aggregate storage is uncapped by default; even a single blob well below the upload limit can exhaust memory during this conversion. Consequently, valid populated stores cannot export their data, including capped stores for which export is explicitly intended to remain available. Use bounded streaming or chunked export rather than retaining the complete binary, numeric-array, and JSON representations simultaneously.

Useful? React with 👍 / 👎.

Comment on lines +521 to +522
const irohHex = this.requireIroh(req);
const store = await this.bridgeProof(req, bindingId, irohHex, "export", new Uint8Array(0));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Provide an export production path for users who lost their key

During a lost-key rebind wait, an authenticated account holder cannot satisfy this proof because it requires the unavailable current Iroh private key. However, §6.1 of doc/2026-10-30T22-45-00Z_design_hosted_provisioning_sso_binding.md explicitly promises export in that situation using a service-signed unkeyed_export manifest, which build_export(..., None, ...) already supports. Searching for produceExportSets, appliedEvents, and export routes shows this is the only production path that enumerates the signed objects; the existing /v1/export returns only KV data and blob metadata. Add a separately service-authenticated production path so the binding service can obtain the complete sets without requiring the lost key.

Useful? React with 👍 / 👎.

Comment on lines +111 to +112
const document = mapGet(ext, "document");
if (document === undefined) return [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include blob citations from notes and chat messages

When content is referenced only by a note or a chat attachment, this early return silently treats it as unreferenced and excludes its bytes from the export. The existing native model also carries blob citations in NoteOp::Create and NoteOp::Revise through their content: DocumentRef fields (crates/id-store/src/notes.rs:41–55), and in chat links with ChatLinkKind::Blob (crates/id-store/src/chat.rs:68–95). A read-only reproduction with a signed note.create and its uploaded content produces one object but zero blobs and empty blob_refs, so restoring the archive loses the note's content despite a successful export. Enumerate all supported blob-carrying payload variants in both this helper and the Rust counterpart.

Useful? React with 👍 / 👎.

* of it, so neither is enumerated here. */
appliedEvents(): HeldEvent[] {
return this.sql
.exec("SELECT author, seq, id, bytes FROM bridge_events ORDER BY author, seq")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict exported events to the applied chain prefix

When a fork is discovered after one branch has already been stored, refreshAuthor() reduces the applied frontier to the fork sequence but retains the branch's rows in bridge_events. This unfiltered query therefore exports events that are no longer applied, while the exporter deliberately omits the competing fork-proof header. In an in-memory reproduction, ingesting e0,a1 followed by conflicting b1 leaves the chain frozen with next_seq: 1, but appliedEvents() returns sequences [0,1]. Restoring that export can reactivate the known-forked branch and its suffix. Filter the enumeration against each author's applied frontier rather than exporting every retained row.

Useful? React with 👍 / 👎.

Conflicts: hosted_export.rs module doc (both slices rewrote the
not-here note) — kept the production section, pointing ingest at
hosted_ingest. Semantic: #13158's hosted_ingest tests built
objects with the synthetic ExportObject::new, which the section
6.3 mapping removes — migrated to ExportObject::from_envelope.
Its not-an-event test's premise (a wrapper-valid non-event
object) is exactly what 6.3 overturns, so the test now asserts
the refusal at verify_import (ObjectSignatureInvalid) instead of
at ingest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id: hosted export production — enumerate a per-user DO's objects and R2 blobs into build_export (slice 4b of #2852, from #3810)

1 participant